package cn.lds.j375.chlm.service.impl;

import cn.lds.j375.chlm.dto.ResultDTO;
import cn.lds.j375.chlm.entity.Menu;
import cn.lds.j375.chlm.mapper.MenuMapper;
import cn.lds.j375.chlm.service.MenuService;
import cn.lds.j375.chlm.utils.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Objects;

public class MenuServiceImpl implements MenuService {

    private SqlSession sqlSession = SqlSessionUtil.getSqlSession();

    private MenuMapper menuMapper = sqlSession.getMapper(MenuMapper.class);;

    @Override
    public ResultDTO<List<Menu>> selectMenuAll() {

        List<Menu> menus = menuMapper.selectMenuAll();

        if (menus == null || menus.size() == 0){
            return ResultDTO.buildError();
        }


        return ResultDTO.buildSuccess(menus);
    }

    @Override
    public ResultDTO<Menu> selectMenuById(Integer id) {

        Menu menu = menuMapper.selectMenuById(id);

        if (Objects.isNull(menu)){
            return ResultDTO.buildError();
        }


        return ResultDTO.buildSuccess(menu);
    }
}
